﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TTQT;
using TTQT.TTQT_Code;

public partial class ProductDetail : MasterControl// System.Web.UI.UserControl
{
   
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request["prdId"];
        
        SanPhamDAO sp = new SanPhamDAO();
        sp.id = id;
        if(!sp.getById())
        {
            Response.Redirect("Default.aspx");
        }
        lblId.Text = sp.id;
        lblGia.Text = TTQT.TTQT_Code.TTQTCommon.formatTien_KhongThapPhan(sp.GiaBanThamKhao);
        lblName.Text = sp.tenHang;
        lblSeri.Text = sp.seri;
        lblTomLuoc.Text = sp.tomLuoc;
        lblNoiDung.Text = sp.noiDung;
        string orgImg = "#";
        try
        {
            orgImg = sp.picUrl.Replace("../", "").Replace("_s.", ".");
            if(orgImg.IndexOf('/')<0)
            {
                orgImg = "#";
            }
        }catch(Exception ex)
        {
            orgImg = "#";
        }
        lblMagic.Text = "";
        lblMagic.Text += "<a style=\"margin: 0 auto; border: 1px solid #333; padding: 2px;\" class=\"MagicZoom\" title=\"Sản phẩm gia truyền\" id=\"A1\" href=\"" + orgImg + "\" rel=\"zoom-width:400;zoom-height:400;\">";
        //lblMagic.Text += "<a href=\"#\">";
        //lblMagic.Text += "<img src=\"" + sp.picUrl.Replace("../", "") + "\" id=\"ProductDetail1_imgSP\" style=\"width: 200px;\" alt=\"Cao xương mèo (CM100)\" /></a>";
        lblMagic.Text += "<img src=\"" + sp.picUrl.Replace("../", "") + "\" id=\"ProductDetail1_imgSP\" style=\"width: 200px;margin: 0 auto; border: 1px solid #333; padding: 2px;\" alt=\"Cao xương mèo (CM100)\" /></a>";
        //lblMagic.Text += "<br /><div class=\"MagicToolboxMessage\">Move your mouse over image</div>";

    }
    protected void cmdDatMua_Click(object sender, EventArgs e)
    {
        SanPhamInfo sanPhamInfo = null;
        int soLuong = TTQTCommon.ToInt32(txtSoLuong.Text, 0);
        if(soLuong<1)
        {
            MyWebUtils.MyWebUtil.alert(Page,"Số lượng mua không hợp lệ!");
            return;
        }
        SanPhamDAO sp=new SanPhamDAO();
        sp.id = lblId.Text;
        sanPhamInfo = sp.getById(sp.id);
        if(sanPhamInfo!=null)
        {
            sanPhamInfo.SoLuongDatMua= TTQTCommon.ToInt32(txtSoLuong.Text, 0);
            GioHang gh = gioHang;
            gh.muaThem(sanPhamInfo);
            gioHang = gh;
        }
        else
        {
            // khong tim thay san pham
        }
        Response.Redirect("CaoMeoCart.aspx");
        
    }
}
